import { Store, Reducer, Action } from './model/redux.model';
const reducer: Reducer<number> = (state: number, action: Action) => {
    switch (action.type) {
        case 'INCREMENT':
            return state + action.payload;
        case 'DECREMENT':
            return state - action.payload;
        default:
            return state;
    }
}

const store: Store<number> = new Store<number>(reducer, 0);

const action1: Action = {
    type: 'INCREMENT',
    payload: 100
}
store.dispatch(action1);
console.log(store.getState());
action1.type = 'DECREMENT';
store.dispatch(action1);
console.log(store.getState());

// 用Store来统一管理State和Reducer是一个不错的思维，但是每一次dispatch更新state的值之后，
// 需要通过getState()来拉取state的值，而不是每一次state发生改变时，store主动推送这一改变